      {  Petrova Tatjana
         2012 / 12 / 09
         This program  draws 400 buttons and you can play with them.}
unit UnitPlayWthButtons;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  arr : array [0..19,0..19] of TButton;
  num: integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i,j : integer;
begin
  for j:=0 to 19 do
  begin
    for i := 0 to 19 do
    begin
      arr[i][j]:= TButton.Create(Form1);
      arr[i][j].Width := 20;
      arr[i][j].Height := 20;
      arr[i][j].Parent := Form1;
      arr[i][j].Top := 20*(j mod 20);
      arr[i][j].Left := 20*(i mod 20);
      arr[i][j].OnClick := Button1Click;
   end;
  end;

end;

procedure TForm1.Button1Click(Sender: TObject);
var i,j: integer;
begin
  for j:=0 to 19 do
  begin
    for i := 0 to 19 do
    begin
      if (Sender=arr[i][j]) then
      begin
        arr[i][j].Enabled := False;
        if( num mod 2=0) then
          arr[i][j].Caption := 'X'
        else
          arr[i][j].Caption := '0';
      end;
    end;
  end;
  num:=num+1;
end;

end.

